package com.maori.languageapp.discover;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import com.maori.languageapp.R;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

public class Maori_Discover_Song_Details extends Activity {
	
	String word;
	String maori;
	String nid;
	String Source;
	ProgressDialog mProgressDialog;
	Bitmap bmImg = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//Remove title bar
	    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.maori_discover_word_details);
		new loadSingleView().execute();
	}

	public class loadSingleView extends AsyncTask<String, String, String> {

		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			// Create a progressdialog
			mProgressDialog = new ProgressDialog(Maori_Discover_Song_Details.this);
			// Set progressdialog title
			mProgressDialog.setTitle("Download Songs Details");
			// Set progressdialog message
			mProgressDialog.setMessage("Loading...");
			mProgressDialog.setIndeterminate(false);
			// Show progressdialog
			mProgressDialog.show();

		}

		@Override
		protected String doInBackground(String... args) {
			try {
				// Retrieve data from ListViewAdapter on click event
				Intent i = getIntent();
				// Get the result of rank
				word = i.getStringExtra("word");
				// Get the result of country
				maori = i.getStringExtra("maori");
				// Get the result of population
				nid = i.getStringExtra("nid");
				// Get the result of flag
				Source = i.getStringExtra("Source");

				// Download the Image from the result URL given by flag
				URL url = new URL(Source);
				HttpURLConnection conn = (HttpURLConnection) url
						.openConnection();
				conn.setDoInput(true);
				conn.connect();
				InputStream is = conn.getInputStream();
				bmImg = BitmapFactory.decodeStream(is);
			} catch (IOException e) {
				Log.e("Error", e.getMessage());
				e.printStackTrace();
			}

			return null;
		}

		@Override
		protected void onPostExecute(String args) {
			// Locate the TextViews in singleitemview.xml
			TextView memdiscover_det_title = (TextView) findViewById(R.id.memdiscover_det_title);
			TextView memdiscover_det_subtitle = (TextView) findViewById(R.id.memdiscover_det_subtitle);
			
			ImageView memdiscover_det_image = (ImageView) findViewById(R.id.memdiscover_det_image);

			// Set results to the TextViews
			memdiscover_det_title.setText(word);
			memdiscover_det_subtitle.setText(word);
			memdiscover_det_image.setImageBitmap(bmImg);

			// Close the progressdialog
			mProgressDialog.dismiss();

		}
	}
}
